<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GoodsCustomfield extends Model
{
    use HasFactory;

    protected $table = 'sp_goods_customfield_2';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //is_delete是否删除  1是 2否
    const GOODS_CUSTOMFIELD_IS_DELETE = 1;//是
    const GOODS_CUSTOMFIELD_NOT_DELETE = 2;//否

    //定义表单项列表
    protected function GetDefineFormList($pageSize, $where)
    {
        $select = array('gc.id', 'gc.category_id', 'gc.field_order', 'gc.field_title', 'gc.field_type', 'gc.field_val', 'gc.must_is', 'gc.create_time', 'c.name');
        $data = $this
            ->from('sp_goods_customfield_2 as gc')
            ->leftjoin('sp_category as c', 'c.id', 'gc.category_id')
            ->select($select)
            ->where($where)
            ->orderBy('gc.id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }

}
